package common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;

public class LoginInterceptor implements HandlerInterceptor {

    private Logger logger = LoggerFactory.getLogger(LoginInterceptor.class);
//    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
//        long beginTime = System.currentTimeMillis();
//        logger.info("开始计时: {}  URI: {}", new SimpleDateFormat("YYYY年 HH:mm:ss.SSS").format(Long.valueOf(beginTime)), httpServletRequest.getRequestURI());
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
//        logger.info("postHandle requestCode:{}", httpServletRequest.getCharacterEncoding());
        if (modelAndView != null){
            logger.info("ViewName: " + modelAndView.getViewName() + ".html");
        }
    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
//        long endTime = System.currentTimeMillis();
//        logger.info("开始计时: {}  URI: {}", new SimpleDateFormat("YYYY年 HH:mm:ss.SSS").format(Long.valueOf(endTime)), httpServletRequest.getRequestURI());
    }
}
